from django.test import TestCase

# Create your tests here.
import openpyxl

def read_excel_dict(path:str):
    """读取excel数据，存储为字典 --- [{},{},{},]"""
    #先实例化一workbook
    workbook = openpyxl.load_workbook(path)
    #实例化一个sheet
    sheet = workbook['student']
    #定义一个变量存储最终的数据 --[]
    students = []
    #准备key,
    keys = ['sno', 'name', 'gender', 'birthday', 'mobile', 'email', 'address']
    #遍历数据
    for row in sheet.rows:
        #定义一个临时的字典
        temp_dict = {}
        #组合值和key
        for index, cell in enumerate(row):
            #组合
            temp_dict[keys[index]] = cell.value
        #附加到list中
        students.append(temp_dict)
    #返回
    return students






# if __name__ == '__main__':
#     path="E:\stu.xlsx"
#     #调用函数
#     student = read_excel_dict(path)
#     #输出
#     print(student)

# import string
# aa = string.ascii_lowercase
# print(aa.index('A'))
# print('A')
# print(ord('A'))
# print(chr(ord('A') + 1))